<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增文件管理')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-file-add">
            <div class="form-group hidden">    
                <label class="col-sm-3 control-label is-required">文件名称：</label>
                <div class="col-sm-8">
                    <input name="fileName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">文件路径：</label>
                <div class="col-sm-8">
                    <input id="filePath" name="filePath" class="form-control" type="file">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">是否公开：</label>
                <div class="col-sm-8">
                    <select name="ispub" class="form-control">
                     <option value="1">公开</option>
                     <option value="2">私密</option>
                 </select>
                </div>
            </div>
            <div class="form-group hidden">    
                <label class="col-sm-3 control-label is-required">创建人编号：</label>
                <div class="col-sm-8">
                    <input name="userId" class="form-control" type="text" required>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/file"
        $("#form-file-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
        	if ($.validate.form()) {
        		uploadFile();
        	}
        }

        function uploadFile() {
        	var formData = new FormData();
        	if ($('#filePath')[0].files[0] == null) {
        		$.modal.alertWarning("请先选择文件路径");
        		return false;
        	}
        	formData.append('fileName', $("#fileName").val());
        	formData.append('file', $('#filePath')[0].files[0]);
        	$.ajax({
        		url: prefix + "/add",
        		type: 'post',
        		cache: false,
        		data: formData,
        		processData: false,
        		contentType: false,
        		dataType: "json",
        		success: function(result) {
        			$.operate.successCallback(result);
        		}
        	});
        }
    </script>
</body>
</html>